package com.mshen.service.model;

import java.util.LinkedList;
import java.util.List;

public class OmitDumplicateMsg {
	
	private List<String> list=new LinkedList<String>();
	
	private int maxsize=2000;
	/**
	 * 判断是否已经接收过此消息,如果存在则删除此元素
	 * @param msgid
	 * @return 
	 */
	public boolean exist(String msgid){
		return list.remove(msgid);
	}
	/**
	 * 设置消息ID
	 * @param id
	 */
	public synchronized void set(String msgid){
		if(list.size()>=maxsize){
			list.remove(0);
			list.add(msgid);
		}else{
			list.add(msgid);
		}
	}
	
	public static void main(String[] args) {
		OmitDumplicateMsg otmsg=new OmitDumplicateMsg();
		otmsg.set("1");
		System.out.println(otmsg.exist("1"));
	}
}
